@PUSHD %~dp0

REM BUILD_NUMBER FORMAT
REM Major.Minor.Patch.BuildNumber

for /F "tokens=1,2,3,4 delims=." %%i in (BUILD_NUMBER) do (
  SET VER_MAJOR=%%i
  SET VER_MINOR=%%j
  SET VER_PATCH=%%k
  SET VER_BUILD=%%l
)
SET/A VER_BUILD=%VER_BUILD% + 1
echo %VER_MAJOR%.%VER_MINOR%.%VER_PATCH%.%VER_BUILD% 1>BUILD_NUMBER

SET VER_BUILD_S=%VER_BUILD%

SET /A FG=%VER_BUILD% / 1000
if {%FG%}=={0} SET VER_BUILD_S=0%VER_BUILD_S%

SET /A FG=%VER_BUILD% / 100
if {%FG%}=={0} SET VER_BUILD_S=0%VER_BUILD_S%

SET /A FG=%VER_BUILD% / 10
if {%FG%}=={0} SET VER_BUILD_S=0%VER_BUILD_S%

SET VER_STRING=%VER_MAJOR%.%VER_MINOR%.%VER_PATCH%.%VER_BUILD_S%

SET VER_FILE=src\com\lognsoft\btest\Version.java

echo /* this file is generated by BUILD_NUM_GEN.BAT*/ 1>%VER_FILE%
echo /* please do not modify this file */ 1>>%VER_FILE%
echo package com.lognsoft.btest; 1>>%VER_FILE%
echo public class Version { 1>>%VER_FILE%
echo public static final int Major=%VER_MAJOR%; 1>>%VER_FILE%
echo public static final int Minor=%VER_MINOR%; 1>>%VER_FILE%
echo public static final int Patch=%VER_PATCH%; 1>>%VER_FILE%
echo public static final int Build=%VER_BUILD%; 1>>%VER_FILE%
echo public static final String VersionString="%VER_MAJOR%.%VER_MINOR%"; 1>>%VER_FILE%
echo public static final String FullVersionString="%VER_STRING%"; 1>>%VER_FILE%
echo }; 1>>%VER_FILE%
echo /*end of Version.java*/ 1>>%VER_FILE%

@POPD
